import 'package:flutter/material.dart';

// 使用有状态组件
// Widget是临时对象，用于构建当前状态下的应用程序
// 而State对象在多次调用build()之间保持不变，允许它们记住信息(状态)
class Counter extends StatefulWidget {

  @override
  State createState() {
    return new _CounterState();
  }

}

class _CounterState extends State<Counter> {

  // 下划线开头只能本类访问
  int _counter = 0;

  @override
  Widget build(BuildContext context) {
    return new Row(
      children: <Widget>[
        new RaisedButton(
          onPressed: _increment,
          child: new Text('累加'),
        ),
        new RaisedButton(onPressed: _reduce,
        child: new Text('减少'),),
        new Text("count : $_counter",style: TextStyle(
          fontSize: 20
        ),),
      ],
    );
  }

  // counter累加
  void _increment() {
    setState(() {
      _counter++;
    });
  }

  void _reduce() {
    setState(() {
      _counter--;
    });
  }

}